package com.sky.controller.user;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.Dishservice;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;
    @Autowired
    Dishservice dishservice;

    //分页查询
    @Cacheable(cacheNames = "setmealCache",key ="'setmeal_'+#categoryId",unless = "#result.data==null||#result.data.size()<1")
    @GetMapping("/list")
    public Result list(Long categoryId) {
        List<Setmeal> setmealsList = setmealService.listByCategoryId(categoryId);
        return Result.success(setmealsList);
    }
    //根据套餐id查询包含的菜品
    @GetMapping("/dish/{id}")
    public Result queryById(@PathVariable Long id){
        List<DishItemVO> list = dishservice.listByCategoryId1(id);
        return Result.success(list);

    }
}